<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue 示例</title>
</head>
<body>
    <div id="app">
        总价：{{prices}}
    </div>

    <script src="http://unpkg.com/vue/dist/vue.min.js"></script>
    <script>
        // 变量app表示一个vue实例
        var app = new Vue({
            el: '#app', //用于指定一个页面中存在的Dom元素来挂载Vue示例。挂载成功后可以使用app.$el来访问该元素
            data: {
                package1: [
                    {
                        name: 'iphone 7',
                        price: 7199,
                        count: 2
                    },
                    {
                        name: 'iPad',
                        price: 2888,
                        count: 1
                    }
                ],
                package2: [
                    {
                        name: 'apple',
                        price: 3,
                        count: 10
                    },
                    {
                        name: 'banana',
                        price: 2,
                        count: 10
                    }
                ]
            },
            computed: {
                prices : function() {
                    var prices = 0;
                    for (var i = 0; i < this.package1.length; i ++){
                        prices += this.package1[i].price * this.package1[i].count;
                    }
                    for (var i = 0; i < this.package2.length; i ++){
                        prices += this.package2[i].price * this.package2[i].count;
                    }

                    return prices;
                }
            }
        })
    </script>
</body>
</html>